#include<iostream>
using namespace std;
#include<vector>
class Solution {
public:
    vector<vector<int>> imageSmoother(vector<vector<int>>& img) {
        vector<vector<int>> now = img;
        int dx[] = { -1,0,1,-1,0,1,-1,0,1 }, dy[] = { 0,0,0,-1,-1,-1,1,1,1 };
        int m = img.size(), n = img[0].size();
        for (int i = 0; i < m; ++i) {
            for (int j = 0; j < n; ++j) {
                int sum = 0, k = 0;
                for (int a = 0; a < 9; ++a) {
                    int x = dx[a] + i, y = dy[a] + j;
                    if (x >= 0 && x < m && y >= 0 && y < n) {
                        sum += img[x][y];
                        ++k;
                    }
                }
                now[i][j] = sum / k;
            }
        }
        return now;
    }
};